<template>
  <section class="setting-bg pv-12 ph-16">
    <h3>预付费水表设置</h3>
    <div class="flex-row-center">
      <span class="fc-regular fs-base">临时用水量(吨)：2 </span>
      <el-button type="warning" link class="ml10" @click="handleEdit">编辑</el-button>
    </div>
    <el-dialog v-model="visible" title="临时用水量(吨)" width="400px" @close="() => visible = false" :fullscreen="mobile">
      <el-form :model="form" ref="formRef">
        <el-form-item prop="temporaryDegree" :rules="[{ required: true, message: '请输入临时用水量(吨)', trigger: 'blur' }, { pattern: /^([1-9]\d{0,3}|1000)$/, message: '请输入1-999之间的正整数', trigger: 'blur' }]">
          <el-input v-model="form.temporaryDegree" placeholder="请输入临时用水量(吨)"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="() => visible = false">取消</el-button>
        <el-button type="primary" @click="handleOk">确认</el-button>
      </template>
    </el-dialog>
  </section>
</template>
<script setup name="PrePaidElectrictable">
import { Check, Close, Remove } from '@element-plus/icons-vue'
import useAppStore from '@/store/modules/app'
import { toRefs } from 'vue'

const { proxy } = getCurrentInstance()

const autoClear = ref(true)
const visible = ref(false)

const data = reactive({
  form: {
    temporaryDegree: 1
  }
})
const { form } = toRefs(data)

const mobile = computed(() => useAppStore().device === 'mobile')

function handleEdit() {
  visible.value = true
}

function handleOk() {
  proxy.$refs['formRef'].validate(valid => {
    if (valid) {
      console.log(form.value);
      visible.value = false
    }
  })
}
</script>
